
#include "stdafx.h"
#include "resource.h"
#include "CRoadNetMaintainAddIn.h"
#include "selectionset.h"
#include "selectionitem.h"
#include "HDiMineView.h"
//#include "CAppSettings.h"
#include "math.h"
#include "HDiMineModel.h"
#include "DBConversion.h"
#include "SelectOperator.h "
#include "WorkPlaneManager.h"
#include "th_md.h"
#include "geoconvert.h"
#include "tw_md.h"
#include "basedefine.h"
#include "SlopeCurveBaseOperator.h"
#include "CRoadNetMaintainAddIn.h"
//#include "hcd.h" 
#include "AddInBaseOperator.h"
#include "dmLayoutBase.h"
#include "dmCreateLayerOut.h"
#include "BCGPMessageBox.h"



CSlopeCurveBaseOperator::CSlopeCurveBaseOperator(HDiMineView* view,IDMAddIn *addin):CAddInBaseOperator(view,addin)
{
	OL_InitOperator();
}
CSlopeCurveBaseOperator::~CSlopeCurveBaseOperator()
{
	if(m_pPolyline) delete []m_pPolyline;
}

void CSlopeCurveBaseOperator::OL_InitOperator()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	strcpy_s(m_oLprompt,"");
	m_oLlastCmdID=0;
	m_oLmode=-1;
	m_PtsCount=0;
	m_ptSArray=0;
	m_ptDArray=0;
	m_oLlpSelSet=m_pView->GetSelection();
	m_oLlp3DBaseView=((CCRoadNetMaintainAddIn*)GetIDMAddIn())->Get3DView();
	ASSERT(m_oLlpSelSet!=0);
	m_pPolyline = 0;
	m_PolylineCount = 0;
	m_oLlpworkplane=m_pView->GetWorkPlaneManager()->GetActiveWorkPlane();
}

void CSlopeCurveBaseOperator::OL_PromptMessage(UINT msgID,CMDLINE_INFO_TYPE type)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	m_oLmode=1;
	m_oLlastCmdID=msgID;
	CString prompt;
	prompt.LoadString(msgID);
	PromptMessage(prompt.GetBuffer(),type);

}
void CSlopeCurveBaseOperator::OL_PromptMessage(char *szMsg,CMDLINE_INFO_TYPE type)
{
	m_oLmode=0;
	strcpy_s(m_oLprompt,szMsg);
	PromptMessage(szMsg,type);
}
BOOL  CSlopeCurveBaseOperator::OL_InsertPolyline(int num, dmDPoint* lppoints)
{
	if((!lppoints)||num<2) return FALSE;
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	CdmDBBase *pDB = m_pView->GetModel()->GetActiveFile();
	if(pDB == 0)
	{
		PromptMessage(IDS_STRING_NOCUR_LAYER);
		return FALSE;
	}
	CdmEntityBase *pEnt = pDB->GetActiveLayer()->InsertPolyline(num,lppoints);
	if(pEnt==0) return FALSE;
	pEnt->Display();
	AddInsertUndoItem(pEnt);
	twModelFunc::Clear(pEnt);
	m_pView->Update();
	return TRUE;
}


BOOL  CSlopeCurveBaseOperator::OL_InsertPolyline(CdmEntityBase *pEntity,int num, dmDPoint* lppoints)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	CdmDBBase *pDB = m_pView->GetModel()->GetActiveFile();
	CdmLayerBase *pLayer;
	pLayer=GetNewDataLayer(pEntity); 
	if(pLayer == 0)
	{
		PromptMessage(IDS_STRING_NOCUR_LAYER);
		return FALSE;
	}
	if(num<2) return FALSE;
	CdmEntityBase *pEnt = pLayer->InsertPolyline(num,lppoints);
	if(pEnt==0||lppoints==0) return FALSE;
	pEnt->Display();
	AddInsertUndoItem(pEnt);
	twModelFunc::Clear(pEnt);
	m_pView->Update();
	return TRUE;
}
BOOL CSlopeCurveBaseOperator::GetActiveLayer(CdmLayerBase*& pActiveLayer)
{
	CdmDBBase *pDB =0;
	pDB =m_pView->GetModel()->GetActiveFile();
	if(pDB==0) return FALSE;
	pActiveLayer=pDB->GetActiveLayer();
	return pActiveLayer!=0;
}
void CSlopeCurveBaseOperator::BCGPMessageFun(UINT idcaption,UINT idcare)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	CString caption,text;
	caption.LoadString(idcaption);
	text.LoadString(idcare);
	BCGPMessageBox(0,(LPCTSTR)text,(LPCTSTR)caption,MB_OK|MB_ICONSTOP);
	return;
}